<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>添加新闻</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="__PLUGIN__/layui/css/layui.css" media="all">
	<style type="text/css">
		.one {
			margin:auto;
			padding: 1rem;
			width: 355px;
			margin-top: 10rem;
			background-color: #1D2631;
		}
		.layui-form-label {
		    float: left;
		    display: block;
		    padding: 9px 0px;
		    width: 43px;
		    font-weight: 400;
		    text-align: right;
		}
		.layui-input-block {
		    margin-left: 57px;
		    min-height: 36px;
		}
        .layui-form-pane .layui-form-label {
            width: 163px;
        }
        .layui-form-pane .layui-input-block {
            margin-left: 166px;
        }
	</style>
</head>
<body>
	<form class="layui-form layui-form-pane" action="javascript:;" style="border: 1px solid #E6E6E6; margin: 10px; padding: 10px;">
		<div class="layui-form-item">
		    <label class="layui-form-label">站点根网址</label>
		    <div class="layui-input-block">
		      	<input type="text" name="cfg_basehost" value="{$params['cfg_basehost']}" required lay-verify="required" autocomplete="off" class="layui-input">
		    </div>
		</div>
        <div class="layui-form-item">
            <label class="layui-form-label">网页主页链接</label>
            <div class="layui-input-block">
                <input type="text" name="cfg_indexurl" value="{$params['cfg_indexurl']}" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">网站名称</label>
            <div class="layui-input-block">
                <input type="text" name="cfg_webname" value="{$params['cfg_webname']}" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">网站版权信息</label>
            <div class="layui-input-block">
                <input type="text" name="cfg_powerby" value="{$params['cfg_powerby']}" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">站点默认关键字</label>
            <div class="layui-input-block">
                <input type="text" name="cfg_keywords" value="{$params['cfg_keywords']}" required lay-verify="required" placeholder="关键词请用英文逗号隔开" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">站点描述</label>
            <div class="layui-input-block">
                <input type="text" name="cfg_description" value="{$params['cfg_description']}" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">网站备案号</label>
            <div class="layui-input-block">
                <input type="text" name="cfg_beian" value="{$params['cfg_beian']}" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-block">
                <input type="text" name="cfg_telephone" value="{$params['cfg_telephone']}" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地址</label>
            <div class="layui-input-block">
                <input type="text" name="cfg_address" value="{$params['cfg_address']}" required lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
		<div class="layui-form-item">
			<div class="layui-input-block">
  				<button class="layui-btn" lay-submit lay-filter="formSub">立即提交</button>
  				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>
    <!-- <div class="layui-input-block">
        <button class="layui-btn" lay-submit onclick="statically(this)">首页静态化</button>
    </div> -->
<script src="__JS__/jquery-3.3.1.min.js"></script>
<script src="__PLUGIN__/layui/layui.js"></script>

<script>
	// var img = '';
	layui.use(['jquery', 'carousel', 'form', 'element', 'layer', 'table', 'flow', 'upload'], function(){
        var $ = layui.jquery
            ,carousel    = layui.carousel
            ,form       = layui.form
            ,element    = layui.element
            ,layer      = layui.layer
            ,table      = layui.table
            ,flow       = layui.flow
            ,upload     = layui.upload;

		// 自定义验证规则
		form.verify({
		    title: function(value){
		      	if(value.length < 5){
		        	return '标题至少得5个字符啊';
		      	}
		    },
		    content: function(value){
		      	layedit.sync(editIndex);
		    }
		});

		//普通图片上传
        var uploadInst = upload.render({
            elem: '#edit_btn'
            ,url: '/admin/common/upimg/'
            ,accept: 'images' //允许上传的文件类型
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#cover').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功
                console.log(res.data.src);
                img = res.data.src;
                $('#demoText').html('');
                return layer.msg('上传成功');
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

		form.on('submit(formSub)', function(data){
			// data.field.file = img;
            var url  = "{:url('System/systemBaseParams')}";
            $.post(url, data.field, function(result) {
                //var result = JSON.parse(result);	// json 字符串 转 对象
                layer.msg(result.message);
                return;
                if (result.status == 1) {
                    setTimeout(function () {
                        window.location.href = "{:url('System/systemBaseParams')}";
                    }, 1000);
                }
            },"JSON");

			console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
			return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});
	});

    // function statically(e) {
    //     $.ajax({
    //         type:"POST",
    //         traditional:true,
    //         url:"{:url('system/indexstatically')}",
    //         data:{},
    //         cache:false,
    //         success:function (data) {
    //             // body...
    //         }
    //     })
    // }
</script>

</body>
</html>
